package com.bml.architect.consumer.service;

import com.bml.architect.DemoService;
import org.apache.dubbo.config.annotation.Method;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.context.ConfigurableApplicationContext;

import java.util.concurrent.CompletableFuture;

//@EnableAutoConfiguration
public class AsyncDemoConsumer {

    @Reference(version = "async",methods = {@Method(name = "sayHelloAsync",async = true)})
    private DemoService demoService;

    public static void main(String[] args) {
        ConfigurableApplicationContext ca = SpringApplication.run(AsyncDemoConsumer.class);

        DemoService demoService = ca.getBean(DemoService.class);
        CompletableFuture<String> future = demoService.sayHelloAsync("bml");
        future.whenComplete((v, t) -> {
            if (t != null) {
                t.printStackTrace();
            } else {
                System.out.println("Response: " + v);
            }
        });
// 早于结果输出
        System.out.println("Executed before response return.");

    }
}
